class Solution {
    public boolean canConstruct(String ransomNote, String magazine) {
        char[] c1 = ransomNote.toCharArray();
        char[] c2 = magazine.toCharArray();

        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < c2.length; i++) {
            Integer cnt = map.get(c2[i]);
            cnt = cnt == null ? 0 : cnt;
            map.put(c2[i], cnt + 1);
        }
        for (int i = 0; i < c1.length; i++) {
            if (map.containsKey(c1[i])) {
                int cnt = map.get(c1[i]);
                if (cnt > 1) {
                    map.put(c1[i], cnt - 1);
                } else {
                    map.remove(c1[i]);
                }
            } else {
                return false;
            }
        }
        return true;
    }
}
